from datetime import date

from sqlalchemy import Date, String
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base_model import EntityMixin, Base


class PythonModel(Base, EntityMixin):
    """ Python模型表 """
    __tablename__ = "python_model"

    # 名称，不可空
    name: Mapped[str] = mapped_column(String(32))
    # 编码，不可空
    code: Mapped[str] = mapped_column(String(32))
    # 描述
    describe: Mapped[str | None] = mapped_column(String(255), name="describe_")
    # 生日
    birthday: Mapped[date | None] = mapped_column(Date)


if __name__ == '__main__':
    from datetime import datetime

    entity = PythonModel(id=1, name="test", code="test", describe="test", birthday=date.today(),
                         create_time=datetime.now(), created_by=1,
                         update_time=datetime.now(), updated_by=1)
    # 打印所有字段，和对应的值
    for column in PythonModel.__mapper__.c.keys():
        value = getattr(entity, column, None)  # 获取字段对应的值
        print(column, value)
        print(getattr(PythonModel, column))
